package com.softlab.logsystem.api;

import com.softlab.logsystem.common.RestData;
import com.softlab.logsystem.common.util.JsonUtil;
import com.softlab.logsystem.core.model.LogVo;
import com.softlab.logsystem.service.ConsumerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author LiXiwen
 * @date 2020/1/7 15:19
 */
@CrossOrigin(origins = "*", allowCredentials = "true", allowedHeaders = "*")
@RestController
public class ConsumerApi {
    private static final Logger logger = LoggerFactory.getLogger(ConsumerApi.class);

    private final ConsumerService consumerService;

    @Autowired
    public ConsumerApi(ConsumerService consumerService) {
        this.consumerService = consumerService;
    }

    @RequestMapping(value = "/logs", method = RequestMethod.POST)
    public RestData selectLogsByCondition(@RequestBody LogVo logVo) {
        logger.info("POST selectLogsByCondition : " + JsonUtil.getJsonString(logVo));
        return consumerService.selectDetailByCondition(logVo);
    }

    @RequestMapping(value = "/apps", method = RequestMethod.GET)
    public RestData selectApps() {
        logger.info("GET selectApps : ");
        return consumerService.selectApps();
    }

}
